<template>
  <div class>
    <div class="outmain ba_f">
      <div class="shuju_title mar_b20">
        <div class="shuju_title_text">
          <span>提现设置</span>
        </div>
      </div>
      <el-form ref="form" :model="form" label-width="180px" class="mar_t20">
        <el-form-item label="提现开关">
          <el-radio-group v-model="form.open">
            <el-radio label="1">开启</el-radio>
            <el-radio label="2">关闭</el-radio>
          </el-radio-group>
          <div class="yb_margin lh16">开启后，门店可以申请提现余额，请谨慎操作</div>
        </el-form-item>
        <div v-if="form.open=='1'">
          <el-form-item label="可提现渠道">
            <el-checkbox-group v-model="form.channel">
              <el-checkbox label="1">微信</el-checkbox>
              <el-checkbox label="2">支付宝</el-checkbox>
              <el-checkbox label="3">银行卡</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="最低提现金额">
            <el-input v-model="form.downMoney" type="number" placeholder="请输入最低提现金额">
              <template slot="append">元</template>
            </el-input>
            <div class="yb_margin lh16">只能填写整数，不填写为不限制</div>
          </el-form-item>
          <el-form-item label="每单抽取费率">
            <el-input v-model="form.rate" type="number" placeholder="请输入每单抽取费率">
              <template slot="append">%</template>
            </el-input>
            <div class="yb_margin lh16">商户申请提现时，每笔申请提现扣除的费用，默认为空，即提现不扣费，支持填写小数；商户入驻时的默认提现费率</div>
          </el-form-item>
          <el-form-item label="提现手续费">
            <el-input v-model="form.rateDownMoney" type="number" placeholder="请输入提现手续费">
              <template slot="prepend">最低</template>
              <template slot="append">元</template>
            </el-input>/
            <el-input v-model="form.rateUpMoney" type="number" placeholder="请输入金额">
              <template slot="prepend">最高</template>
              <template slot="append">元</template>
            </el-input>
            <div class="yb_margin lh16">商户提现时，提现费用的上下限，最高为空时，表示不限制扣除的提现费用</div>
          </el-form-item>
          <el-form-item label="提现间隔周期">
            <el-input v-model="form.day" type="number" placeholder="请输入提现间隔周期">
              <template slot="append">天</template>
            </el-input>
            <div class="yb_margin lh16">提现周期设置为0， 表示不限制提现周期。</div>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="mar_t20 ba_f pad_20 t_c">
      <el-button type="primary" @click="submitForm">保存</el-button>
    </div>
  </div>
</template>
<script>
import { getConfig, postConfig } from '@/api/setup';
export default {
  created() {
    this.init();
  },
  data() {
    return {
      form: {
        open: '2',
        channel: ['1'],
        downMoney: '',
        rate: '',
        rateDownMoney: '',
        rateUpMoney: '',
        day: ''
      }
    };
  },
  methods: {
    async init() {
      const { data } = await getConfig({ ident: 'withdrawal' });
      this.form2 = this.form;
      this.form = Object.assign(this.form2, data);
    },
    submitForm() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          if(+this.form.downMoney < +this.form.rateDownMoney){
            this.$baseMessage('最低提现金额应大于最低提现手续费', 'error');
            return
          }
          this.form.ident = 'withdrawal';
          const { msg } = await postConfig(this.form);
          this.$baseMessage(msg, 'success');
          this.init();
        } else {
          return false;
        }
      });
    }
  }
};
</script>
